from ftp import FtpSender
import shutil

class TransDely(object):
	def __init__(self, local_path):
		self.files      = []
		self.recipeDely = None
		self.local_path = local_path
		self.errors	= None

	def SendFtp(self, files, recipeDely):
		self.ftp        = FtpSender()
		self.files      = files
		self.recipeDely = recipeDely
		
		(ret, self.errors) = self.ftp.Connect(self.recipeDely.Host, self.recipeDely.User, self.recipeDely.Passwd)
		if ret:
			(ret, self.errors) = self.ftp.Cwd(self.recipeDely.Path)
			if ret:
				for f in files:
					(ret, self.errors) = self.ftp.Send(self.local_path + f, f)
					if ret == False:
						break;
				
		self.ftp.Disconnect()
		return ret

	def SendLocal(self, files, recipeDely):
		for f in files:
			shutil.copy(self.local_path + f, recipeDely.Path)

		
	def Send(self, files, recipeDely):
		if recipeDely.Type == 'FTP':
			return self.SendFtp(files, recipeDely)
		else:
			return self.SendLocal(files, recipeDely)

		
